//
//  PrexFile.swift
//  DemoNavBar
//
//  Created by YangHuan on 2019/12/12.
//  Copyright © 2019 YangHuan. All rights reserved.
//

import UIKit

//屏高
let kScreenHeight = UIScreen.main.bounds.size.height
//屏宽
let kScreenWidth = UIScreen.main.bounds.size.width

//iPhonex以上判断
let IS_IPhoneX_All = (kScreenHeight == 812 || kScreenHeight == 896)

//导航栏高
let HYDevice_NaviBar_Height = (IS_IPhoneX_All ? 88 : 64)
//状态栏高

let HYDevice_StatusBar_Height = (IS_IPhoneX_All ? 44 : 20)

//选项卡高

let HYDevice_TabBar_Height = (IS_IPhoneX_All ? 83 : 49)

//安全区高
let HYDevice_SafeArea_BottomHeight = (IS_IPhoneX_All ? 34 : 0)

//相对于 750 宽的屏幕比例

let kScreenWidth_SCALE_47: CGFloat = kScreenWidth/375.0

let kScreenHeight_SCALE_47: CGFloat = kScreenHeight/667.0
/**宽度比例*/

func KWidth_ScaleWidth(_ font:CGFloat) -> (CGFloat) {
   return (kScreenWidth/375)*font
}

/**高度比例*/
func KHeight_ScaleHeight(_ font:CGFloat) -> (CGFloat) {
  return  kScreenHeight/667*font

}
/**字体比例*/

func KFont_ScaleFont(_ font:CGFloat) -> (CGFloat) {

    return  kScreenWidth/375*font

}
//便利化 字体

func kBoldSystemFont(font: CGFloat) -> (UIFont) {

    return UIFont.boldSystemFont(ofSize: font)

}

func kSystemFont(font: CGFloat) -> (UIFont) {

    return UIFont.systemFont(ofSize: font)

}
/**RGBA的颜色设置*/
func RGB(_ r:CGFloat, g:CGFloat, b:CGFloat) -> UIColor {

    return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: 1.0)

}

func RGBA(_ r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) -> UIColor {

    return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a)

}

func HEXAColor(hexValue: Int, a: CGFloat) -> (UIColor) {

    return UIColor(red: ((CGFloat)((hexValue & 0xFF0000) >> 16)) / 255.0,

                  green: ((CGFloat)((hexValue & 0xFF00) >> 8)) / 255.0,

                  blue: ((CGFloat)(hexValue & 0xFF)) / 255.0,

                  alpha: a)

}

func HEXColor(hexValue: Int) -> (UIColor) {
    
    return HEXAColor(hexValue: hexValue, a: 1.0)

}


//便利化 UserDefaults

let kUserDefaults: UserDefaults = UserDefaults.standard

//便利化 AppDelegate

let kAppDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate

//便利化 Notification

let kNotification: NotificationCenter = NotificationCenter.default

func kNotificationPost (name: String){

    kNotification.post(name: NSNotification.Name(rawValue: name), object: nil)

}

//打印信息D
func DLog<T>(_ message : T, file : String = #file, funcName : String = #function, lineNum : Int = #line) {
    #if DEBUG
        let fileName = (file as NSString).lastPathComponent
        print("\n>>> \(Date())  \(fileName) (line: \(lineNum)): \(message)\n")
    #endif
}
// MARK: ============================================================================
// MARK: Dictory Array Strig Object 闭包方式
///过滤null对象
public let kFilterNullOfObj:((Any)->Any?) = {(obj: Any) -> Any? in
    if obj is NSNull {
        return nil
    }
    return obj
}

///过滤null的字符串，当nil时返回一个初始化的空字符串
public let kFilterNullOfString:((Any)->String) = {(obj: Any) -> String in
    if obj is String {
        return obj as! String
    }
    return ""
}

/// 过滤null的数组，当nil时返回一个初始化的空数组
public let kFilterNullOfArray:((Any)->Array<Any>) = {(obj: Any) -> Array<Any> in
    if obj is Array<Any> {
        return obj as! Array<Any>
    }
    return Array()

}

/// 过滤null的字典，当为nil时返回一个初始化的字典
public let kFilterNullOfDictionary:((Any) -> Dictionary<AnyHashable, Any>) = {( obj: Any) -> Dictionary<AnyHashable, Any> in
    if obj is Dictionary<AnyHashable, Any> {
        return obj as! Dictionary<AnyHashable, Any>
    }
    return Dictionary()
}





